<template>
    <div class="form-box">
        <el-form ref="form" :model="form" label-position="left">
            <el-row :gutter="20">
                <el-col :span="11">
                    <el-form-item label="进度阶段" label-width="100px">
                        <el-select v-model="progress" @change="onChange()">
                            <el-option v-for="item in progressItems" :key="item.value" :label="item.name" :value="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="13">
                    <el-form-item label="进度年月" label-width="100px" >
                        <el-date-picker  type="month"  v-model="currentDate" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd hh:mm:ss">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="计划阶段投资" label-width="130px">
                            <el-input v-model="form.currentInvestment"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="11">
                    <el-form-item label="计划累计投资" label-width="140px">
                            <el-input v-model="form.accumulativeInvestment"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="计划累计形象进度">
                <el-input type="textarea" row="4" v-model="form.consContent"></el-input>
            </el-form-item>
            <el-form-item label="累计形象进度">
                <el-input type="textarea" row="4" v-model="form.consContent"></el-input>
            </el-form-item>
            <el-form-item label="推进中的问题">
                <el-input type="textarea" row="4" v-model="form.consContent"></el-input>
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" row="4" v-model="form.consContent"></el-input>
            </el-form-item>
            <el-row :gutter="20">
                <div class="commit-btn">
                    <el-button type="primary"  v-on:click="submit()">提交</el-button>
                </div>
            </el-row>
        </el-form>
    </div>
</template>
<script>
    import date_formate from "../tool/Global/dateutil.js";
    import {projectType,projectProgress} from "../tool/Global/app-config.js";
    import {queryProjectScheduleByPkid,addProjectSchedule,updateProjectSchedule} from "../tool/Global/app-mgr.js";
    export default {
        props: ['pkid','projDepartmentID','projDepartment','projCreatePersonID','projCreatePerson'],
        data:function(){
            return{
                progressItems:projectProgress,
                form:{
                    projectID:sessionStorage.getItem("projectId"),
                    currentStage:"",
                    currentInvestment:"",
                    currentImage:"",
                    accumulativeInvestment:"",
                    accumulativeImage:"",
                    problems:"",
                    note:"",
                    createPersonID:"41",
                    createPerson:"超级管理员"
                },
                currentDate:"",
                progress:""              
            }
        },
        mounted:function(){
            let ref = this;
            this.$nextTick(function () {
                if(ref.pkid){
                    ref.form.pkid = ref.pkid;
                    queryProjectScheduleByPkid(ref.pkid).then(function(result){
                        if(result.data.success){
                            let data = result.data.data;
                            for(var key in ref.form){
                                ref.form[key] = (data[key]==null || data[key]=="")?data[key]:'';
                            }
                            ref.progress = ref.form.currentStage?ref.progressItems[ ref.form.currentStage-1].name:'';
                            ref.currentDate = data.currentDate?date_formate.format(new Date(data.currentDate),"yyyy/MM/dd hh:mm:ss"):'';
                        }
                    })
                }
            })
        },
        methods:{
            submit(){
                var data = {                      
                    projectSchedule:JSON.stringify(this.form),
                    currentDate:this.currentDate                       
                }
                let ref = this;
                let params = new URLSearchParams()
                for (var key in data) {
                    params.append(key, data[key])
                }
                if(this.form.pkid){
                    /*$.ajax({
                        url:this.GLOBAL.projectDetailUrl,
                        type:"put",
                        data:data,
                        success:function(result){
                            
                        }
                    })*/
                    updateProjectSchedule(params).then(function(result){
                        if(result.data.success){
                            ref.$emit("listenClose");
                        }
                    })
                }else{
                    addProjectSchedule(params).then(function(result){
                        if(result.data.success){
                            ref.$emit("listenClose");
                        }
                    })
                } 
            },
            onChange(){
                for(var i=0;i<this.progressItems.length;i++){
                    if(this.progress == this.progressItems[i].name){
                        this.form.currentStage = this.progressItems[i].value;
                    }
                }
            }
        }
    }
</script>
<style scoped>
    .commit-btn{
        text-align: center;
    }
</style>


